package com.mysql.test;

import com.mysql.cj.jdbc.Driver;
import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UpdateData {
    @Test
    public void updateData() throws SQLException {
        Driver driver = new Driver();
        DriverManager.registerDriver(driver);
        String url = "jdbc:mysql://localhost:3306/db01";
        String username = "root";
        String password = "123321";
        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(connection);
        String sql="update user set iphone='123456789'";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        int i = preparedStatement.executeUpdate();
        if (i>0){
            System.out.println("修改成功");
        }
        else {
            System.out.println("修改失败");
        }
        preparedStatement.close();
        connection.close();
    }
}
